package HuaWeiPractice;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Test20210417 {
    public static void main(String[] args) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.MONTH, 0);
        Date month = c.getTime();
        String nowM = sdf.format(month);
        System.out.println("nowM:"+nowM);

        Calendar c1 = Calendar.getInstance();
        c1.setTime(new Date());
        c1.add(Calendar.MONTH, -1);
        Date mon1 = c1.getTime();
        String nowM1 = sdf.format(mon1);
        System.out.println("nowM1:"+nowM1);

        Calendar c3 = Calendar.getInstance();
        c3.setTime(new Date());
        c3.add(Calendar.MONTH, -3);
        Date mon3 = c3.getTime();
        String nowM3 = sdf.format(mon3);
        System.out.println("nowM3:"+nowM3);

        Calendar year = Calendar.getInstance();
        year.setTime(new Date());
        year.add(Calendar.MONTH, -12);
        Date y_ago = year.getTime();
        String year1_ago = sdf.format(y_ago);
        System.out.println("year1_ago:"+year1_ago);

    }
}
